import * as types from './mutations-type'
import { shuffle, copyArr } from '../common/js/index'

export const selectPlay = function({commit, state}, {list, index}) {
  commit(types.SET_FULL_SCREEN, true)
  commit(types.SET_PLAYING, true)
  commit(types.SET_CURRENT_INDEX, index)
  commit(types.SET_SEQUENCE_LIST, list)
  commit(types.SET_PLAY_LIST, list)
}

export const randomPlayAll = function({commit, state}, {list}) {
  commit(types.SET_FULL_SCREEN, false)
  commit(types.SET_PLAYING, true)
  commit(types.SET_CURRENT_INDEX, 0)
  commit(types.SET_SEQUENCE_LIST, list)
  commit(types.SET_MODE, 1)
  let playlist = shuffle(copyArr(list))
  commit(types.SET_PLAY_LIST, playlist)
}

export const searchPlay = function({commit, state}, {list, index}) {
  commit(types.SET_FULL_SCREEN, true)
  commit(types.SET_PLAYING, true)
  commit(types.SET_SEQUENCE_LIST, list)
  commit(types.SET_PLAY_LIST, list)
  commit(types.SET_CURRENT_INDEX, index)
}
